<template>
  <div class="page-content padding-top">
    <item @click.native="selectItem()">不限车系</item>
    <item v-for="item in arr" @click.native="selectItem(item.seriesId,item.seriesName)">{{item.seriesName}}</item>
  </div>
</template>
<script>
import { bus } from 'bus.js'
import modelModal from '../sort/model.vue'
 // ...

  export default {
    data() {
      return {
        arr:[],
        brandJson:{},
        modelModal:null
      }
    },
    mounted(){
      $modal.fromComponent(modelModal, {
        title: '车型选择',
        theme: 'assertive',
        onHide: () => {
          // console.log();
        }
      }).then((modal) => {
        this.modelModal = modal;
      });
    },
    destroyed(){
      if (this.modelModal)
        $modal.destroy(this.modelModal)
    },
    created(){
      bus.$on('toSeries', (obj) => {
        this.arr = [];
        this.brandJson = obj;

        var _this = this;
        axios.get(baseUrl+'/controller/getSeriesList',{params:{
            brandId:obj.brandId
          }
        })
        .then(function(res){
          _this.arr = res.data.result;
        })
      });
      bus.$on('hideAll', (text) => {
        this.modelModal.hide();
      });
    },
    methods: {
      selectItem(a,b){
        if (a) {
          this.brandJson.seriesId = a;
          this.brandJson.seriesName = b;
          bus.$emit('toModel', this.brandJson);
          this.modelModal.show();
        }else{
          bus.$emit('brandJson',this.brandJson);
        }
        
      }
    }
  }
</script>

